package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppQianDaoRecord;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterQianDaoRecordDao.java
 * @Description 签到记录
 * @createTime 2021年07月23日 18:34:00
 */
@Repository
public class AfterQianDaoRecordDao extends BaseDao<AppQianDaoRecord> {

    /**
     * 新增或更新
     * @param appQianDaoRecord
     */
    public void saveOrUpdate(AppQianDaoRecord appQianDaoRecord) {
        if (appQianDaoRecord.getId() == null || appQianDaoRecord.getId() == 0) {
            appQianDaoRecord.setId(this.add(appQianDaoRecord));
        } else {
            this.update(appQianDaoRecord);
        }
    }

    /**
     * 综合查询
     */
    public List<AppQianDaoRecord> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_qiandao_record where 1=1 ");
        if (StringEx.isNotNull(paramap.get("userid"))) {
            str.append(" and userid = ? ");
            list.add(paramap.get("userid"));
        }
        if (StringEx.isNotNull(paramap.get("nick"))) {
            str.append(" and nick = ? ");
            list.add(paramap.get("nick"));
        }
        str.append(" order by createtime desc ");
        String sql = str.toString();

        return this.queryList(sql, list, AppQianDaoRecord.class, splitPageBean);
    }

    /**
     * 获取用户获取当日签到记录
     * @param userid
     * @return
     */
    public AppQianDaoRecord getByUserId(Integer userid) {
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_qiandao_record where to_days(createtime) = to_days(now()) and userid = ? ");
        List<Object> list = new ArrayList<>();
        list.add(userid);
        String sql = str.toString();
        return this.queryObj(sql, list, AppQianDaoRecord.class);
    }


}